package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// 通用返回
func Response(c *gin.Context, httpStatus int, code int, data gin.H, msg string){

	resultBody := gin.H{"code":code, "msg":msg}
	for k := range data {
		resultBody[k] = data[k]
	}
	c.JSON(httpStatus, resultBody)
}

// 成功返回
func Success(c *gin.Context, data gin.H, msg string){
	Response(c, http.StatusOK, 200, data, msg)
}
// 失败返回
func Fail(c *gin.Context, data gin.H, msg string){
	Response(c, http.StatusBadRequest, 400, data, msg)
}
